package com.xy.job;

import java.util.List;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import com.xy.entity.Company;
import com.xy.service.CompanyService;
import com.xy.util.DateStringUtil;

/**
 * 定时任务
 * 
 * implements StatefulJob 实现该接口，定时任务不存在多线程，下一个定时任务的开启，会等待上一个任务结束
 * 
 * @author 陈耀
 * @date 2018-2-5
 */
public class SpringJobTime extends QuartzJobBean implements StatefulJob {
	private Logger log = Logger.getLogger(SpringJobTime.class);
	private CompanyService companyService;

	public void setCompanyService(CompanyService companyService) {
		this.companyService = companyService;
	}

	@Override
	protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
		// 开始日志
		log.info(DateStringUtil.getDateToString() + "定时任务开始！！");
		// 定时到指定的FTP服务器拿文件
		List<Company> companyList = companyService.selectCompanyList(null);
		for (Company company : companyList) {
			System.out.println(company);
		}
		// 解析文件
		// 入库
		// 结束日志
		log.info(DateStringUtil.getDateToString() + "定时任务结束！！");
	}

}
